package fr.uvsq.isty.bdh.hchess.gui.menu;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JButton;

/**
 *
 * @author Florent Hemmi <florent.hemmi@gmail.com>
 */
public class CustomButton extends JButton {
    
     private String name;
     private static Image img;
         
     public CustomButton(String str){
            super(str);
            this.name = str;

            try {
                img = ImageIO.read(getClass().getClassLoader()
                                .getResource("menu/button.png"));
            } catch (IOException e) {
            }
            this.setPreferredSize(new Dimension(100, 50));
     }
    
    @Override
     public void paintComponent(Graphics g){
                 
        Graphics2D g2d = (Graphics2D)g;
            
        GradientPaint gp = new GradientPaint(0, 0, Color.blue, 0, 20, Color.cyan, true);
        g2d.setPaint(gp);
        g2d.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
        
        g2d.setColor(Color.black);
        g2d.drawString(this.name, this.getWidth() / 2 - (this.getWidth() / 5), (this.getHeight() / 2) + 5);
     }
}
